package br.com.getdiscount.tcc;

import br.com.getdiscount.base.service.DefaultService;
import br.com.getdiscount.tcc.service.LotecaService;
import br.com.getdiscount.tcc.service.PrecoService;
import br.com.getdiscount.tcc.sets.SpringFactory;

public class GdServiceLocator {

	private static GdServiceLocator gdServiceLocator;

	private GdServiceLocator() {
	}

	public static GdServiceLocator getInstance() {
		if (gdServiceLocator == null) {
			gdServiceLocator = new GdServiceLocator();
		}
		return gdServiceLocator;
	}

	private <T extends DefaultService> T getService(Class<T> _class) {
		String canonicalName = _class.getCanonicalName();
		int lastDot = canonicalName.lastIndexOf(".");
		String _name = canonicalName.substring(lastDot + 1);
		char charZero = _name.charAt(0);
		String retorno = String.valueOf(charZero).toLowerCase() + _name.substring(1);
		return (T) SpringFactory.getInstance().getBean( retorno );
	}
	
	
	/*public LotecaService getLotecaService() {
		return this.getService(LotecaService.class);
	}*/
	
	public PrecoService getPrecoService() {
		return this.getService(PrecoService.class);
	}
}